#pragma once

//////////////////////////////////////////////////////////////////////////

#include "resource.h"

//////////////////////////////////////////////////////////////////////////

#include <sstream>

#ifdef UNICODE
using std::wostringstream;
using std::wstring;
#   define _tostringstream wostringstream
#   define _tstring        wstring
#else
using std::ostringstream;
using std::string;
#   define _tostringstream ostringstream
#   define _tstring        string
#endif

using std::ostream;
using std::endl;

struct PrintStream
{
    _tostringstream out_;

    PrintStream(void) : out_(_T("")) {}

    void zip(void)
    {
        _tstring str(out_.str());
        size_t sz = str.size();
        if (sz <= 2000) return;
        str.clear();
        out_.str(str);
    }

#ifdef UNICODE
    PrintStream& operator << (const char* con)
    {
        int wcs_len = MultiByteToWideChar(CP_ACP, NULL, con, strlen(con), NULL, 0);
        wchar_t* wcs_str = new wchar_t[wcs_len + 1];
        MultiByteToWideChar(CP_ACP, NULL, con, strlen(con), wcs_str, wcs_len);
        wcs_str[wcs_len] = L'\0';
        out_ << wcs_str;
        delete [] wcs_str;
        zip();
        return (*this);
    }
    PrintStream& operator << (ostream& (*fn)(ostream&))
    {
        if (fn == endl) out_ << _T("\n");
        zip();
        return (*this);
    }
#else
    PrintStream& operator << (ostream& (*fn)(ostream&))
    {
        out_ << fn;
        zip();
        return (*this);
    }
#endif

    template <typename T>
    PrintStream& operator << (T& con)
    {
        out_ << con;
        zip();
        return (*this);
    }

    template <typename T>
    PrintStream& operator << (const T& con)
    {
        out_ << con;
        zip();
        return (*this);
    }
} strout;

#define CODECHECK_CUSTOM_STROUT

//////////////////////////////////////////////////////////////////////////

#include "test_head.h"

//////////////////////////////////////////////////////////////////////////
